package easy;

/*
1184. 公交站间的距离
解题思路：两次循环求得正向和反向的结果，返回小的那个
 */
public class LeeCode1184 {

  public int distanceBetweenBusStops(int[] distance, int start, int destination) {

    int res1 = 0;
    int res2 = 0;
    for (int i = start; i!=destination; i=(i + 1) % distance.length) {
      res1 = distance[i] + res1;
    }
    for (int i = destination; i!=start ; i=(i + 1) % distance.length) {
      res2 = distance[i] + res2;
    }
    return Math.min(res1,res2);
  }

  public static void main(String[] args) {
    System.out.println(new LeeCode1184().distanceBetweenBusStops(new int[]{1,2,3,4},0,3));
  }
}
